var gadgets =
{
  json:
  {
    stringify: function(o)
    {
      return JSON.stringify(o);
    },
    parse: function(s)
    {
      return JSON.parse(s);
    }
  },
  util:
  {
    registerOnLoadHandler: function(init)
    {
      window.setTimeout(init, 100)
      var g = _gel("gadget");
      g.style.height = "";
      g.style.width = "";
      g.style.backgroundColor = "";
    }
  },
  window:
  {
    adjustHeight: function(){}
  }
}
var wave =
{
  isInWaveContainer: function(){return true},
  _setStateUpdated: null,
  setStateCallback: function(stateUpdated)
  {
    this._setStateUpdated = stateUpdated;
  },
  _setModeUpdated: null,
  setModeCallback: function(modeUpdated)
  {
    this._setModeUpdated = modeUpdated;
  },
  stateWrapper:{
    submitDelta: function(delta)
    {
      for(var prop in delta)
      {
        if(delta[prop] == null)
        {
          delete wave.state[prop];
      }else{
          wave.state[prop] = delta[prop];
        }
      }
      if(wave._setStateUpdated)setTimeout(wave._setStateUpdated, 100);
    },
    getKeys: function()
    {
      var res = [];
      for(var prop in wave.state)
      {
        res.push(prop);
      }
      return res;
    },
    get: function(k)
    {
      return wave.state[k];
    },
  },
  getState: function(){return wave.stateWrapper;},
  state: {
  },
  getMode: function()
  {
    return _modeValue;
  },
  Mode: {PLAYBACK:1, EDIT:2, VIEW:3},
  ui: {
    loadCss: function(){},
    makeButton: function(){},
  }
  
  
}
var _gel = function(id){return document.getElementById(id);}


var _triggerModeCallBack = function(mode)
{
  _modeValue = mode;
  wave._setModeUpdated(mode);
}
var _modeValue = null;
